﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;

using Willson.JsbManager.Idal;
using Willson.JsbManager.Entity;
using Willson.JsbManager.BllEntity;

namespace Willson.JsbManager.Bll
{
    /// <summary>
    /// 用户登陆管理类
    /// </summary>
    public class BLLLogin:BaseBLL
    {
        private ITableXtUser Dal = null;

        public BLLLogin()
        {
            Dal = Reflect<ITableXtUser>.Create("DAL_table_xt_user", "Willson.JsbManager.Dal");
        }

        /// <summary>
        /// 返回所有登陆用户名
        /// </summary>
        /// <returns>用户名类列</returns>
        public List<string> GetUserList()
        {
            IEnumerator<string> ator = Dal.GetItemString("name").GetEnumerator();
            List<string> list = new List<string>();

            while (ator.MoveNext())
            {
                    
                list.Add(ator.Current.ToString());
            }

            return list;
        }

        /// <summary>
        /// 登陆验证
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns>存在则返回<c>true</c>，否则为<c>false</c>。</returns>
        public bool Authentication(string name, string pwd)
        {
            string hs_pwd = string.Empty;
            Hashtable ht = new Hashtable();

            hs_pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5").ToLower();

            ht.Add("name", name);
            ht.Add("pwd", hs_pwd);

            return Dal.IsExistKey(ht);
        }

        /// <summary>
        /// 查询用户ID号
        /// </summary>
        /// <param name="user_name">用户名</param>
        /// <returns>用户ID</returns>
        public int GetUserID(string user_name)
        {
            Hashtable ht = new Hashtable();

            ht.Add("name",user_name);

            return Dal.FindPrimaryKey(ht);           
        }
    }
}
